package main

import (
	v5 "CryptoTest/v5"
)

func main() {
	//对称加密
	//fmt.Println("des 加密")
	//src := []byte("abcd")
	//key := []byte("12345678")
	//iv := []byte("87654321")
	//encryptStr := string(util.DesEncrypt(src, key, iv))
	//fmt.Println("des 加密后: ", encryptStr)
	//decryptStr := string(util.DesDecrypt([]byte(encryptStr), key, iv))
	//fmt.Println("des 解密后: ", decryptStr)
	//
	//fmt.Println("aes 加密")
	//key = []byte("1234567812345678")
	//iv = []byte("8765432112345678")
	//encryptStr = string(util.AesEncrypt(src, key, iv))
	//fmt.Println("aes 加密后: ", encryptStr)
	//decryptStr = string(util.AesDecrypt([]byte(encryptStr), key, iv))
	//fmt.Println("aes 解密后: ", decryptStr)
	//非对称加密
	//创建秘钥对
	//util.GenerateRsaKey(1024)
	//src := []byte("你好啊啊啊啊啊啊啊啊啊啊啊")
	//encrypt := util.RSAEncrypt(src, "public.pem")
	//decrypt := util.RSADecrypt(encrypt, "private.pem")
	//fmt.Println("rsa 解密后: ", string(decrypt))
	//src := []byte("caspar")
	//md5Sum := util.Md5Sum(src)
	//fmt.Println("md5Sum:  ", md5Sum)
	//sha256 := util.Sha256Sum(src)
	//fmt.Println("sha256:  ", sha256)

	//src := []byte("caspar")
	//key := []byte("123456")
	//generateHamc := util.GenerateHamc(sha256.New, src, key)
	//verifyHamcOk := util.VerifyHamc(sha256.New, src, key, generateHamc)
	//fmt.Println("verifyHamcOk:  ", verifyHamcOk)

	//src := []byte("caspar")
	//signRSA := util.SignRSA(src, "private.pem", crypto.SHA256)
	//verifySignRSAOK := util.VerifySignRSA(src, signRSA, "public.pem", crypto.SHA256)
	//fmt.Println("verifySignRSAOK:  ", verifySignRSAOK)

	//util.GenerateECDSAKey(util.GetRandomString(36))

	//src := []byte("caspar")
	//rText, sText := util.SignECDRSA(src, "ec-private.pem")
	//verifySignECDRSA := util.VerifySignECDRSA(src, rText, sText, "ec-public.pem")
	//fmt.Println("verifySignECDRSA:  ", verifySignECDRSA)

	//验证未通过
	//src := []byte("caspar")
	//eccEncrypt, err := util.ECCEncrypt(src, "ec-public.pem")
	//if err != nil {
	//	panic(err)
	//}
	//eccDecrypt, _ := util.ECCDecrypt(eccEncrypt, "ec-private.pem")
	//if err != nil {
	//	panic(err)
	//}
	//fmt.Println("util.ECCDecrypt:  ", string(eccDecrypt))

	////获取随机字符串
	//randomKey := myECIES.GetRandomString(40)
	//
	////生成私钥和公钥
	//e := myECIES.GenerateKey(randomKey)
	//if e != nil {
	//	fmt.Println(e)
	//}
	//
	////加密前源信息
	//srcInfo := "GO 密码学 —— ECIES 椭圆曲线实现数据加解密"
	//fmt.Println("原文：", srcInfo)
	//
	////加密信息
	//cryptData, e := myECIES.EnCryptByEcies(srcInfo, myECIES.PUBLICFILE)
	//if e != nil {
	//	fmt.Println(e)
	//}
	//fmt.Println("ECIES加密后为：", cryptData)
	//
	////解密信息
	//srcData, e := myECIES.DeCryptByEcies(cryptData, myECIES.PRIVATEFILE)
	//if e != nil {
	//	fmt.Println(e)
	//}
	//fmt.Println("ECIES解密后为：", srcData)

	//demo.GetBTCTotal()

	//demo.PowTest001()

	//demo.BoltDBTest()

	//v2 版本
	//newBlockChain := v2.NewBlockChain()
	//newBlockChain.AddBlock("张三给李四转了1个BTC")
	//newBlockChain.AddBlock("李四给王五转了2个BTC")
	//for index, block := range newBlockChain.Blocks {
	//	fmt.Println(" ============== current block 高度 index :", index)
	//	fmt.Printf("Version : %d\n", block.Version)
	//	fmt.Printf("PrevBlockHash : %x\n", block.PreHash)
	//	fmt.Printf("Hash : %x\n", block.Hash)
	//	fmt.Printf("MerkleRoot : %x\n", block.MerkleRoot)
	//	fmt.Printf("TimeStamp : %d\n", block.Timestamp)
	//	fmt.Printf("Difficuty : %d\n", block.Difficulty)
	//	fmt.Printf("Nonce : %d\n", block.Nonce)
	//	fmt.Printf("Data : %s\n", block.Data)
	//}

	//v3版本
	//var cli = v3.CLI{}
	//cli.Run()

	//v4版本
	var cli = v5.CLI{}
	cli.Run()

	//newBlockChain := v3.NewBlockChain()
	//newBlockChain.AddBlock("张三给李四转了1个BTC")
	//newBlockChain.AddBlock("李四给王五转了2个BTC")
	//var it = v3.BlockChainIterator{
	//	newBlockChain.DB,
	//	newBlockChain.TailHash,
	//}
	//for {
	//	block := it.Next()
	//	fmt.Println(" ===========================================================")
	//	fmt.Printf("Version : %d\n", block.Version)
	//	fmt.Printf("PrevBlockHash : %x\n", block.PreHash)
	//	fmt.Printf("Hash : %x\n", block.Hash)
	//	fmt.Printf("MerkleRoot : %x\n", block.MerkleRoot)
	//	fmt.Printf("TimeStamp : %d\n", block.Timestamp)
	//	fmt.Printf("Difficuty : %d\n", block.Difficulty)
	//	fmt.Printf("Nonce : %d\n", block.Nonce)
	//	fmt.Printf("Data : %s\n", block.Data)
	//	if len(block.PreHash) == 0 {
	//		fmt.Println("打印所有区块完成!")
	//		break
	//	}
	//}

}
